package C;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class C3My {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
//        ArrayList<HashSet<Integer>> teams = new ArrayList<>();

        ArrayList<HashSet<Integer>> teams = new ArrayList<>();
        HashMap<Integer,Integer> memberToTeam = new HashMap<>();


        for (int i = 0;i<m;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();

            if (c == 0) {
                Integer teamIndexA = memberToTeam.get(a);
                Integer teamIndexB = memberToTeam.get(b);
                if (teamIndexA == null && teamIndexB == null) {
                    HashSet<Integer> teamSet = new HashSet<>();
                    teamSet.add(a);
                    teamSet.add(b);
                    teams.add(teamSet);
                    memberToTeam.put(a,teams.size());
                    memberToTeam.put(b,teams.size());
                } else if (teamIndexA != null && teamIndexB == null) {
                    HashSet<Integer> teamSet = teams.get(teamIndexA-1);
                    teamSet.add(b);
                    memberToTeam.put(b,teamIndexA);
                } else if (teamIndexA == null && teamIndexB != null) {
                    HashSet<Integer> teamSet = teams.get(teamIndexB-1);
                    teamSet.add(a);
                    memberToTeam.put(a,teamIndexB);
                } else if (teamIndexA != teamIndexB) {
                    HashSet<Integer> teamSetA = teams.get(teamIndexA-1);
                    HashSet<Integer> teamSetB = teams.get(teamIndexB-1);
                    teamSetA.addAll(teamSetB);
                    for(int member : teamSetB) {
                        memberToTeam.put(member,teamIndexA);
                    }
                }
            } else if (c == 1) {
                Integer teamIndexA = memberToTeam.get(a);
                Integer teamIndexB = memberToTeam.get(b);
                if (teamIndexA != null && teamIndexA.equals(teamIndexB)) {
                    System.out.println("we are a team");
                } else {
                    System.out.println("we are not a team");
                }
            } else if (c!=0&&c!=1 || a>n || b>n) {
                System.out.println("da pian zi");
            }
        }

/*            if(c!=0 && c!=1 || a>n || b>n){
                System.out.println("da pian zi");
                break;
            }
            else if(c==0){
                if (teams.size()==0){
                    teams.add(new HashSet<>());
                    teams.get(0).add(a);
                    teams.get(0).add(b);
                } else { int flag = 0;
                    for (int j=0;j< teams.size();j++){
                        if(teams.get(j).contains(a)){
                            teams.get(j).add(b);
                            flag = 1;
                        }
                        else if (teams.get(j).contains(b)){
                            teams.get(j).add(a);
                            flag = 1;
                        }

                    }
                    if(flag == 0){
                        HashSet<Integer> teamSet = new HashSet<>();
                        teamSet.add(a);
                        teamSet.add(b);
                        teams.add(teamSet);
                    }

                }

            }
            else if(c==1) {
                HashSet<Integer> teamsSet = new HashSet<>();
                int flag = 0;
                for (int j = 0; j < teams.size(); j++) {
                    if (teams.get(j).contains(a) && teams.get(j).contains(b)) {
                        flag = 1;
                    }
                }
                if (flag == 0) {
                    System.out.println("we are not a team");

                } else {
                    System.out.println("we are a team");
                }
            }
        }*/




//        for(int i=0;i<teams.size();i++){
//            for(int x : teams.get(i)) {
//                System.out.println(x+" ");
//            }
//        }

    }
}
